﻿using System.Collections.Generic;
using System.Text;
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.IO;
using System.Xml;

namespace Ramparts
{
    public class AnimatedTile : GameComponent
    {

        float timer;
        int frameCount = 0;
        float interval = 100;
        List<Rectangle> frames;
        int currentFrame;

        public AnimatedTile(Texture2D texture, int frameCount)
        {
            this.texture = texture;
            this.frameCount = frameCount;
            frames = new List<Rectangle>();
            currentFrame = 0;
            frameCount = 2;
        }

        public void Draw(int x, int y, SpriteBatch spriteBatch)
        {
            /* draw the tile */
            spriteBatch.Draw(
                texture,
                new Vector2(x, y),
                frames[currentFrame],
                Color.White);
        }

        public override void Update(GameTime gameTime)
        {

            timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (timer > interval)
            {
                currentFrame++;
                if (currentFrame > frames.Count - 1)
                {
                    currentFrame = 0;
                }
                timer = 0f;
            }

        }

        public void addFrame(Rectangle rectangle)
        {

            frames.Add(rectangle);

        }


    }

}